package fr.mairie.parc.page.user;

import java.util.List;

import javax.annotation.Resource;

import org.apache.click.control.Form;
import org.apache.click.control.PageLink;
import org.apache.click.dataprovider.DataProvider;
import org.apache.click.util.Bindable;
import org.springframework.context.ApplicationContext;

import fr.mairie.parc.context.AppContext;
import fr.mairie.parc.control.materiel.MaterielFields;
import fr.mairie.parc.control.materiel.MaterielTable;
import fr.mairie.parc.control.user.UserFields;
import fr.mairie.parc.control.user.UserTable;
import fr.mairie.parc.domain.Materiel;
import fr.mairie.parc.domain.User;
import fr.mairie.parc.page.BorderPage;
import fr.mairie.parc.page.materiel.EditMaterielPage;
import fr.mairie.parc.page.materiel.ViewMaterielPage;
import fr.mairie.parc.service.MaterielManager;
import fr.mairie.parc.service.UserManager;

public class ListUserPage extends BorderPage{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@Resource protected UserManager userManager;
	@Bindable protected UserTable resultTable = new UserTable("resultTable", this, ViewUserPage.class);
	@Bindable protected Form bottomButtons = new Form("bottomButtons");

	protected UserFields fields = new UserFields();

	public ListUserPage() {

		resultTable.setDataProvider(new DataProvider<User>() {
			private static final long serialVersionUID = 1L;
			public Iterable<User> getData() {
				List<User> res = userManager.selectAll();
		    	return res;
		    }
		});

		PageLink validationRowLink = new PageLink("Validate", EditUserPage.class);
		validationRowLink.setImageSrc("/assets/images/16x16/application_form_edit.png");
		validationRowLink.setTitle("Edit Validation");
		//validationRowLink.setParameter("referrer", "list-user-dif-request.htm");

		resultTable.addActionColumnLink(validationRowLink);
	}

	@Override
	public void onInit() {
		super.onInit();
		ApplicationContext ctx = AppContext.getApplicationContext();
    	userManager = (UserManager) ctx.getBean("userManager");
	}

}
